<?php
class ModelSaleCouponcard extends Model {

	public function getTotalCouponcards() {
      	return $this->db->queryOne("SELECT COUNT(*) AS total FROM  @@couponcard");
	}
   
   public function getCouponcards($filter = null) {
		$sql = "SELECT c.couponID,c.lowAmount,c.highAmount,c.reward FROM  @@couponcard c";

		if ($filter) {
			$sql .= $filter->sort('c.reward', 'ASC');
			$sql .= $filter->limit();
		}
		
		$query = $this->db->query($sql);

		return $query->rows;
	}

	public function addCouponcard($data) {
		$this->db->insert('couponcard', $data);
	}

	public function addCouponcards($datas) {
		foreach ($datas as $data) {
			$this->db->insert('couponcard', $data);
		}
		
	}

    public function deleteCouponcard($couponIDs=null){

        foreach ($couponIDs as $couponID) {
        	 $this->db->query("DELETE FROM  @@couponcard WHERE couponID = ".$couponID);
        }
   }

    public function clearCouponcard(){
       $this->db->query("DELETE FROM  @@couponcard ");
   }
}
?>